package com.yiqi.huize.mvp.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.EditText
import com.flyco.dialog.widget.base.BaseDialog
import com.jess.arms.utils.ArmsUtils
import com.yiqi.huize.onClick
import com.yiqi.news.R
import kotlinx.android.synthetic.main.dialog_input.*

class InputDialog(context: Context?) : BaseDialog<InputDialog>(context) {

    private var mOnCommitListener: OnCommitListener? = null

    fun setOnCommitListener(onCommitListener: OnCommitListener) {
        this.mOnCommitListener = onCommitListener
    }

    init {
        widthScale(0.8f)
    }

    override fun onCreateView(): View {
        return LayoutInflater.from(mContext).inflate(R.layout.dialog_input, null, false)
    }

    override fun setUiBeforShow() {

        tv_cancel.onClick {
            dismiss()
        }

        tv_sure.onClick {
            var content = edt_content.text.toString()
            mOnCommitListener?.onCommit(content)
            dismiss()
        }
    }

    fun setHint(hint: String) {
        edt_content.hint = hint
    }

    fun setTitle(title: String) {
        tv_title.text = title
    }

    fun getEtView(): EditText {
        return edt_content
    }

    override fun dismiss() {
        ArmsUtils.hideKeyboard(edt_content)
        super.dismiss()
    }


    interface OnCommitListener {
        fun onCommit(content: String)
    }
}
